﻿using Base;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;

namespace Model
{


    [Serializable]
    public class cms_article_attr_val
    {
        private readonly EFContext _context;
        public cms_article_attr_val(EFContext context)
        {
            _context = context;
        }
        #region 
        [Key]
        /// <summary>
        /// id
        /// </summary>		
        public int id { get; set; }

        /// <summary>
        /// attr_id
        /// </summary>		
        public int attr_id { get; set; }
        /// <summary>
        /// val_name
        /// </summary>		
        public string val_name { get; set; }
        /// <summary>
        /// val_short_des
        /// </summary>		
        public string val_short_des { get; set; }
        /// <summary>
        /// val_sort
        /// </summary>		
        public int val_sort { get; set; }
        #endregion
        #region  帮助方法
        public IList<cms_article_attr_val> getCategoryAttrValList(int attr_id = 0)
        {
            IList<cms_article_attr_val> articleAttrValList = _context.cms_article_attr_val.AsNoTracking().Where(item => item.attr_id == attr_id).OrderBy(item => item.val_sort).ToList();
            return articleAttrValList;
        }
        /// <summary>
        /// 获取文章选中属性
        /// </summary>
        /// <param name="list"></param>
        /// <param name="attr_id"></param>
        /// <returns></returns>
        public IList<cms_article_attr_val> getArticleAttrValList(List<PulicInt> list, int attr_id)
        {

            var attr_value_id = list.Where(item => item.intId_0 == attr_id).Select(item => item.intId_1).ToArray();
            IList<cms_article_attr_val> articleAttrValList = _context.cms_article_attr_val.AsNoTracking().Where(item => attr_value_id.Contains(item.id)).OrderBy(item => item.val_sort).ToList();
            return articleAttrValList;
        }
        #endregion
    }
}
